#include "DebugLog.h"
#include <d3d9.h>
#include <dxerr.h>

#ifdef _DEBUG
	DebugLog* DebugLog::__ = 0;
	DebugLog* DebugLog::_()
	{
		return ( __ ) ? __ : __ = new DebugLog;
	}
	DebugLog::DebugLog( )
	{
		countMessages = 0;
		debugLog.open( "DebugLog.txt" );
	}

	DebugLog::~DebugLog( )
	{
		debugLog.close();
		__ = 0;
	}
	
	//bool DebugLog::CheckForDxError( TCHAR* file, int line, HRESULT hr )
	//{
	//	if ( !FAILED( hr ) )
	//		return true;

	//	TCHAR desc[ 1024 ];
	//	wsprintf( desc, TEXT( "(DX) %s - %s" ), DXGetErrorString( hr ), DXGetErrorDescription( hr ) );

	//	TCHAR buf[ 2048 ];
	//	wsprintf( buf, TEXT( "%s(%d) : Error: %s\n" ), file, line, desc);
	//	debugLog << buf << std::endl;
	//	//OutputDebugString( buf );

	//	//DebugBreak();
	//	return false;
	//}

	void DebugLog::trace( std::wstring string )
	{
		OutputDebugString( string.c_str() );
	}

	void DebugLog::trace( int num )
	{
		TCHAR buf[ 64 ];
		wsprintf( buf, TEXT( "%d\n" ), num );
		OutputDebugString( buf );
	}

	TraceFunction::TraceFunction( TCHAR* funcName ) : _funcName( funcName )
	{
		TCHAR desc[ 1024 ];
		wsprintf( desc, TEXT( "%s %s\n" ), TEXT( "-->" ), _funcName );

		OutputDebugString( desc );
	}

	TraceFunction::~TraceFunction( )
	{
		TCHAR desc[ 1024 ];
		wsprintf( desc, TEXT( "%s %s\n" ), TEXT( "<--" ), _funcName );

		OutputDebugString( desc );
	}
#endif

